//
//  NNNotify.m
//  iPhoneX
//
//  Created by liaoyp on 2017/12/12.
//  Copyright © 2017年 liaoyp. All rights reserved.
//

#import "NNNotify.h"
#import <UserNotifications/UserNotifications.h>


@implementation NNNotify


+ (void)sendiOS10LocalNotification:(NNNotify *)item
{
    if (item == nil || item.fireDate == nil) {
        return;
    }
    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
    content.body = item.eventName;
    content.badge = @(1);
    content.userInfo = item.userInfo;
    content.sound = [UNNotificationSound defaultSound];
    
    NSTimeInterval timeInsterval = 1;// [item.fireDate timeIntervalSince1970];
    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInsterval repeats:item.isRepeat];
    
    NSString *identifier = @"notificaiton_identifier";
    if (item.userInfo && [item.userInfo objectForKey:@"remindId"]) {
        identifier = [item.userInfo objectForKey:@"remindId"];
    }
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
    [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
        NSLog(@"iOS 10 发送推送， error：%@", error);
    }];
}


@end
